/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package softwareControl;

import grammaticalClasses.event.simpleClasses.AlarmOpen;
import grammaticalClasses.nwConsole.GetNetwork;
import grammaticalClasses.nwConsole.GetPaths;
import grammaticalClasses.nwConsole.GetSystem;
import grammaticalClasses.nwConsole.ParseException;
import grammaticalClasses.nwConsole.ShowCliSessions;
import grammaticalClasses.nwConsole.ShowMote;
import grammaticalClasses.nwConsole.ShowStatus;
import grammaticalClasses.nwConsole.TokenMgrError;
import grammaticalClasses.nwConsole.simpleClasses.Frame;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author FUNDAC
 */
public class TesteComandos {
    
    private SearchCommands buscaComandos;
    
    private ArrayList<String> comandosSolicitados;
    private ArrayList<Object> solucaoComandos;
    
    public TesteComandos(){
    
        ArrayList<String> comandos = new ArrayList<>();
        comandos.add("ShowCliSessions");
        comandos.add("ShowFrame");
        comandos.add("ShowGw");
        comandos.add("ShowMote");
        comandos.add("ShowMsg");
        comandos.add("ShowMsgV");
        comandos.add("ShowOptim");
        comandos.add("ShowSessions");
        comandos.add("ShowStatCur");
        comandos.add("ShowStatNet");
        comandos.add("ShowStatDay");
        comandos.add("ShowStatLife");
        comandos.add("ShowStatShort");
        comandos.add("ShowStatus");
        comandos.add("ShowTime");
        comandos.add("ShowVer");
        comandos.add("GetAcls");
        comandos.add("GetAlarms");
        comandos.add("GetBlacklist");
        comandos.add("GetNetwork");
        comandos.add("GetPaths");
        comandos.add("GetRedundancy");
        comandos.add("GetSecurity");
        comandos.add("GetSla");
        comandos.add("GetSystem");
        comandos.add("GetUsers");
        
        comandos.add("AlarmOpen");
        comandos.add("AlarmClose");

        comandosSolicitados = comandos;
        buscaComandos = new SearchCommands(comandos);
        solucaoComandos = buscaComandos.getCommandsAnswer();
    }
    
    public TesteComandos(ArrayList<String> comandos){
    
        comandosSolicitados = comandos;
        buscaComandos = new SearchCommands(comandosSolicitados);
        solucaoComandos = buscaComandos.getCommandsAnswer();
    }
    
    public Integer buscarIndice(String comando){
        Integer retorno = null;
        
        if(comandosSolicitados != null){
            for(int i=0; i< comandosSolicitados.size(); i++){
                if(comandosSolicitados.get(i).equals(comando)){
                    retorno = i;
                }
            }
        }
        
        return retorno;
    }
    
    public void testeGetPaths() {
        
        Integer indice = buscarIndice("GetPaths");
        
        StringBuilder blocoGetPaths = new StringBuilder();
        
        GetPaths getPathsAux;
        for(int j=0; j< ((ArrayList<GetPaths>) solucaoComandos.get(indice)).size(); j++){
            getPathsAux = ((ArrayList<GetPaths>) solucaoComandos.get(indice)).get(j);
            
        }

    }
    
    public void testeShowMote(){
    
        Integer indice = buscarIndice("ShowMote");
        
        StringBuilder blocoShowMote = new StringBuilder();
        
        ShowMote showMoteAux;
        for(int j=0; j< ((ArrayList<ShowMote>) solucaoComandos.get(indice)).size(); j++){
            showMoteAux = ((ArrayList<ShowMote>) solucaoComandos.get(indice)).get(j);
            
            blocoShowMote.append("\nshow mote getIdMote ").append(showMoteAux.getIdMote()).append("\n");
            blocoShowMote.append("getDevice.getMAC: ").append(showMoteAux.getDevice().getMAC());
            blocoShowMote.append(" getDevice.getAgr: ").append(showMoteAux.getDevice().getAge());
            blocoShowMote.append(" getDevice.getId: ").append(showMoteAux.getDevice().getId());
            blocoShowMote.append(" getDevice.getSwVersion ").append(showMoteAux.getDevice().getSwVersion());
            blocoShowMote.append(" getDevice.getHwVersion ").append(showMoteAux.getDevice().getHwVersion());
            
            blocoShowMote.append("\ngetMoteType ").append(showMoteAux.getMoteType()).append("\n");
            blocoShowMote.append(" getHops ").append(showMoteAux.getHops());
            blocoShowMote.append(" getLate ").append(showMoteAux.getLate());
            blocoShowMote.append(" getTtl ").append(showMoteAux.getTtl()).append("\n");
            blocoShowMote.append("getDistSourceRoute ").append(showMoteAux.getDistSourceRoute());
            blocoShowMote.append(" getPrimSourceRoute ").append(showMoteAux.getPrimSourceRoute());
            blocoShowMote.append(" getSecSourceRoute ").append(showMoteAux.getSecSourceRoute()).append("\n");
            blocoShowMote.append("getPowerSource ").append(showMoteAux.getPowerSource()).append("\n");
            blocoShowMote.append("getAdvertisement ").append(showMoteAux.getAdvertisement()).append("\n");
            
            blocoShowMote.append("getNumFreeTS ").append(showMoteAux.getNumFreeTS()).append("\n");
            
            blocoShowMote.append("getBandwidth.getOutPlanned ").append(showMoteAux.getBandwidth().getOutPlanned());
            blocoShowMote.append(" getBandwidth.getOutCurrent ").append(showMoteAux.getBandwidth().getOutCurrent()).append("\n");
            blocoShowMote.append("getBandwidth.getGlobalService ").append(showMoteAux.getBandwidth().getGlobalService());
            blocoShowMote.append(" getBandwidth.getGlobalDelta ").append(showMoteAux.getBandwidth().getGlobalDelta()).append("\n");
            blocoShowMote.append("getBandwidth.getLocalGoal ").append(showMoteAux.getBandwidth().getLocalGoal());
            blocoShowMote.append(" getBandwidth.getLocalCurrent ").append(showMoteAux.getBandwidth().getLocalCurrent()).append("\n");
            blocoShowMote.append("getBandwidth.getBandforServices ").append(showMoteAux.getBandwidth().getBandforServices());
            blocoShowMote.append(" getBandwidth.getBandforChild ").append(showMoteAux.getBandwidth().getBandforChild());
            blocoShowMote.append(" getBandwidth.getBandFree ").append(showMoteAux.getBandwidth().getBandFree()).append("\n");
            if(showMoteAux.getBandwidth().getParent() != null){
            for(int k=0; k< showMoteAux.getBandwidth().getParent().size(); k++){
                blocoShowMote.append("getBandwidth.getParent.get #").append(showMoteAux.getBandwidth().getParent().get(k));
                blocoShowMote.append(" getBandwidth.getBandParent.get ").append(showMoteAux.getBandwidth().getBandParent().get(k)).append(" ");
            }
            }
            blocoShowMote.append("\ngetBandwidth.getMoteServBW ").append(showMoteAux.getBandwidth().getMoteServBW()).append("\n");
            
            blocoShowMote.append("getNeighbors ").append(showMoteAux.getNeighbors());
            blocoShowMote.append(" getLinks ").append(showMoteAux.getLinks()).append("\n");
            blocoShowMote.append("getLinksSecond ").append(showMoteAux.getLinksSecond()).append(" getLimitLinksSecond ").append(
                    showMoteAux.getLimitLinksSecond()).append("\n");
            
            if(showMoteAux.getFrames() != null){
            for (int k = 0; k < showMoteAux.getFrames().size(); k++) {
                blocoShowMote.append("\ngetFrames.get.getIdFrame ").append(showMoteAux.getFrames().get(k).getIdFrame());
                blocoShowMote.append(" getFrames.get.getNeighbors ").append(showMoteAux.getFrames().get(k).getNeighbors());
                blocoShowMote.append(" getFrames.get.getParents ").append(showMoteAux.getFrames().get(k).getParents());
                blocoShowMote.append(" getFrames.get.getLinksRx ").append(showMoteAux.getFrames().get(k).getLinksRx());
                blocoShowMote.append(" getFrames.get.getLinksTx ").append(showMoteAux.getFrames().get(k).getLinksTx()).append("\n");
                
                if(showMoteAux.getFrames().get(k).getBroadcastLink() != null){
                blocoShowMote.append("getFrames.get.getBroadcastLink.get.getNumberOne ...getNumberTwo ...getNumberThree : ...getLetters\n"
                        + "\tgetFrames.get.getBroadcastLink.get.getMotes.get \n");
                for(int g=0; g< showMoteAux.getFrames().get(k).getBroadcastLink().size(); g++){
                    blocoShowMote.append(" ").append(showMoteAux.getFrames().get(k).getBroadcastLink().get(g).getNumberOne());
                    blocoShowMote.append(".");
                    blocoShowMote.append(showMoteAux.getFrames().get(k).getBroadcastLink().get(g).getNumberTwo());
                    blocoShowMote.append(".");
                    blocoShowMote.append(showMoteAux.getFrames().get(k).getBroadcastLink().get(g).getNumberThree());
                    blocoShowMote.append(" : ");
                    blocoShowMote.append(showMoteAux.getFrames().get(k).getBroadcastLink().get(g).getLetters());
                    
                    if(showMoteAux.getFrames().get(k).getBroadcastLink().get(g).getMotes() != null){
                    for(int u=0; u<showMoteAux.getFrames().get(k).getBroadcastLink().get(g).getMotes().size(); u++){
                        blocoShowMote.append(" #").append(
                            showMoteAux.getFrames().get(k).getBroadcastLink().get(g).getMotes().get(u));
                    }
                    }
                    
                    blocoShowMote.append("\n");
                }
                }
                
                if(showMoteAux.getFrames().get(k).getLink() != null){
                blocoShowMote.append("getFrames.get.getLink.get.getDirecao ...getId ...getNumeroLink1 ...getNumeroLink2"
                        + "...getNumeroLink3 ...getRSSI ...getQ\n");
                for(int g=0; g< showMoteAux.getFrames().get(k).getLink().size(); g++){
                    blocoShowMote.append("\n ").append(showMoteAux.getFrames().get(k).getLink().get(g).getDirecao());
                    blocoShowMote.append(" ").append(showMoteAux.getFrames().get(k).getLink().get(g).getId());
                    blocoShowMote.append(" ").append(showMoteAux.getFrames().get(k).getLink().get(g).getNumeroLink1());
                    blocoShowMote.append("/").append(showMoteAux.getFrames().get(k).getLink().get(g).getNumeroLink2());
                    blocoShowMote.append("/").append(showMoteAux.getFrames().get(k).getLink().get(g).getNumeroLink3());
                    blocoShowMote.append(" ").append(showMoteAux.getFrames().get(k).getLink().get(g).getRSSI());
                    blocoShowMote.append(" ").append(showMoteAux.getFrames().get(k).getLink().get(g).getQ());
                }
                }
            }
            }
        }
        
        System.out.println("");
        System.out.println(blocoShowMote.toString());
        System.out.println("");
        
    }
    
    public void testeShowStatus(){
    
        Integer indice = buscarIndice("ShowStatus");
        
        StringBuilder blocoShowStatus = new StringBuilder();
        
        ShowStatus showStatusAux;
        for(int j=0; j< ((ArrayList<ShowStatus>) solucaoComandos.get(indice)).size(); j++){
            showStatusAux = ((ArrayList<ShowStatus>) solucaoComandos.get(indice)).get(j);
            
            blocoShowStatus.append("\nshow status \n");
            blocoShowStatus.append(showStatusAux.getDataCurrent());
            blocoShowStatus.append(" ").append(showStatusAux.getHourCurrent()).append("\n");
            blocoShowStatus.append(showStatusAux.getAsn()).append("\n");
            blocoShowStatus.append(showStatusAux.getDaysElapsed());
            blocoShowStatus.append(" ").append(showStatusAux.getHourElapsed()).append("\n\n");
            
            blocoShowStatus.append(showStatusAux.getManagerVersion()).append("\n");
            blocoShowStatus.append(showStatusAux.getRedundancyState()).append("\n");
            blocoShowStatus.append(showStatusAux.getNetlayerMode()).append("\n\n");
            
            blocoShowStatus.append(showStatusAux.getGatewayVersion());
            blocoShowStatus.append(" ").append(showStatusAux.getStateGateway()).append("\n");
            for(int i=0; i< showStatusAux.getNameIp().size(); i++){
                blocoShowStatus.append(" ").append(showStatusAux.getNameIp().get(i));
                blocoShowStatus.append(" ").append(showStatusAux.getIpAddress().get(i));
            }
            blocoShowStatus.append("\n");

            blocoShowStatus.append(showStatusAux.getTsTime()).append("\n");
            blocoShowStatus.append(showStatusAux.getOffsets()).append("\n");
            blocoShowStatus.append(showStatusAux.getModeStatus()).append("\n");
            blocoShowStatus.append(showStatusAux.getApChannel()).append("\n");
            blocoShowStatus.append(showStatusAux.getMaxMotes()).append("\n");
            blocoShowStatus.append(showStatusAux.getNetworkMotes()).append("\n");
            blocoShowStatus.append(showStatusAux.getLiveMotes()).append("\n");
            blocoShowStatus.append(showStatusAux.getConnectedMotes()).append("\n");
            blocoShowStatus.append(showStatusAux.getNoLostMotes()).append("\n");
            blocoShowStatus.append(showStatusAux.getOfMotes()).append("\n");
            blocoShowStatus.append(showStatusAux.getActivating()).append("\n");
            blocoShowStatus.append(showStatusAux.getHardwareCTS()).append("\n");
            blocoShowStatus.append(showStatusAux.getRemoteLog()).append("\n");
            blocoShowStatus.append(showStatusAux.getUtcDrift()).append("\n");
            
        }
        
        System.out.println("");
        System.out.println(blocoShowStatus.toString());
        
    }
    
    public void testeGetNetwork(){
        Integer indice = buscarIndice("GetNetwork");
        
        StringBuilder blocoGetNetwork = new StringBuilder();
        
        GetNetwork getNetworkAux;
        for(int j=0; j< ((ArrayList<GetNetwork>) solucaoComandos.get(indice)).size(); j++){
            getNetworkAux = ((ArrayList<GetNetwork>) solucaoComandos.get(indice)).get(j);
            
            blocoGetNetwork.append("\nget network\n");
            blocoGetNetwork.append("[getNetName] ").append(getNetworkAux.getNetName()).append("\n");
            blocoGetNetwork.append("[getNetworkId] ").append(getNetworkAux.getNetworkId()).append("\n");
            blocoGetNetwork.append("[getOptimizationEnable] ").append(getNetworkAux.getOptimizationEnable()).append("\n");
            blocoGetNetwork.append("[getMaxMotes] ").append(getNetworkAux.getMaxMotes()).append("\n");
            blocoGetNetwork.append("[getNumMotes] ").append(getNetworkAux.getNumMotes()).append("\n");
            blocoGetNetwork.append("[getAcessPointPA] ").append(getNetworkAux.getAcessPointPA()).append("\n");
            blocoGetNetwork.append("[getCcaEnabled] ").append(getNetworkAux.getCcaEnabled()).append("\n");
            blocoGetNetwork.append("[getRequestedBasePkPeriod] ").append(getNetworkAux.getRequestedBasePkPeriod()).append("\n");
            blocoGetNetwork.append("[getMinServicesPkPeriod] ").append(getNetworkAux.getMinServicesPkPeriod()).append("\n");
            blocoGetNetwork.append("[getMinPipePkPeriod] ").append(getNetworkAux.getMinPipePkPeriod()).append("\n");
            blocoGetNetwork.append("[getBandwidthProfile] ").append(getNetworkAux.getBandwidthProfile()).append("\n");
            blocoGetNetwork.append("[getManualUSFrame] ").append(getNetworkAux.getManualUSFrame()).append("\n");
            blocoGetNetwork.append("[getManualDSFrame] ").append(getNetworkAux.getManualDSFrame()).append("\n");
            blocoGetNetwork.append("[getManualAdvFrame] ").append(getNetworkAux.getManualAdvFrame()).append("\n");
            blocoGetNetwork.append("[getNetQueue] ").append(getNetworkAux.getNetQueue()).append("\n");
            blocoGetNetwork.append("[getUserQueue] ").append(getNetworkAux.getUserQueue()).append("\n");
            
        }
        
        System.out.println(blocoGetNetwork.toString());
        System.out.println("");
        
    }
    
    public void testeGetSystem(){
        Integer indice = buscarIndice("GetSystem");
        
        StringBuilder blocoGetSystem = new StringBuilder();
        
        GetSystem getSystemAux;
        for(int j=0; j< ((ArrayList<GetSystem>) solucaoComandos.get(indice)).size(); j++){
            getSystemAux = ((ArrayList<GetSystem>) solucaoComandos.get(indice)).get(j);
            
            blocoGetSystem.append("\nget system\n");
            blocoGetSystem.append("[getSystemName] ").append(getSystemAux.getSystemName()).append("\n");
            blocoGetSystem.append("[getLocation] ").append(getSystemAux.getLocation()).append("\n");
            blocoGetSystem.append("\t[getCtrlTcpPort] ").append(getSystemAux.getCtrlTcpPort()).append("\n");
            blocoGetSystem.append("\t[getCtrlSslPort] ").append(getSystemAux.getCtrlSslPort()).append("\n");
            blocoGetSystem.append("\t[getDataTcpPort] ").append(getSystemAux.getDataTcpPort()).append("\n");
            blocoGetSystem.append("\t[getDataSslPort] ").append(getSystemAux.getDataSslPort()).append("\n");
            blocoGetSystem.append("\t[getDiscoveryUdpPort] ").append(getSystemAux.getDiscoveryUdpPort()).append("\n");
            blocoGetSystem.append("\t[getSslEnabled] ").append(getSystemAux.getSslEnabled()).append("\n");
            blocoGetSystem.append("[getSwRev] ").append(getSystemAux.getSwRev()).append("\n");
            blocoGetSystem.append("[getHwModel] ").append(getSystemAux.getHwModel()).append("\n");
            blocoGetSystem.append("[getHwRev] ").append(getSystemAux.getHwRev()).append("\n");
            blocoGetSystem.append("[getSerialNumber] ").append(getSystemAux.getSerialNumber()).append("\n");
            blocoGetSystem.append("[getTime] ").append(getSystemAux.getTime()).append("\n");
            blocoGetSystem.append("[getStartTime] ").append(getSystemAux.getStartTime()).append("\n");
            blocoGetSystem.append("[getCliTimeout] ").append(getSystemAux.getCliTimeout()).append("\n");
            blocoGetSystem.append("[getControllerSwRev] ").append(getSystemAux.getControllerSwRev()).append("\n");
                    
        }
        
        System.out.println(blocoGetSystem.toString());
        System.out.println("");
    }
    
    public void testeAlarmOpen(){
    
        Integer indice = buscarIndice("AlarmOpen");
        
        StringBuilder blocoAlarmOpen = new StringBuilder();
        
        AlarmOpen alarmOpenAux;
        for(int j=0; j< ((ArrayList<AlarmOpen>) solucaoComandos.get(indice)).size(); j++){
            alarmOpenAux = ((ArrayList<AlarmOpen>) solucaoComandos.get(indice)).get(j);
         
            blocoAlarmOpen.append("\n").append(alarmOpenAux.getNumberRegister());
            blocoAlarmOpen.append(" pathOpen ").append(alarmOpenAux.getTimeStamp());
            blocoAlarmOpen.append(" ").append(alarmOpenAux.getAlarmDescript());
            blocoAlarmOpen.append(" ").append(alarmOpenAux.getStatus());
            blocoAlarmOpen.append(" ").append(alarmOpenAux.getMAC());
            blocoAlarmOpen.append(" ").append(alarmOpenAux.getParameter4());
        }
        
        System.out.println(blocoAlarmOpen.toString());
        System.out.println("");
    }
    
}

